﻿using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Resources;

using CE.User;
using CE.Global;
using CE.Database;
using CE.Report;


public partial class telereport_agent_tesco_summary : System.Web.UI.Page
{
    string PageCode = "GGRPTTRAGTESS";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null)
        {
            Response.Redirect("~/ManagementSecureLogin.aspx");
        }

        if (!IsPostBack)
        {
            if (Convert.ToInt64(Session[General.UserId].ToString()) != 1)
            {
                CheckPageAccess();
            }
            if (Session[CE.Global.General.UserRole] != null && Session[CE.Global.General.UserRole].ToString() == "200")
            {
                hplBacktoMenu.Visible = true;
            }
            else
            {
                hplBacktoMenu.Visible = false;
            }


            lblError.Text = "";
            lblContent.Text = "";
            ddlDay1.Visible = true;
            lblFromDate.Text = "Date :";
            lblToDate.Visible = false;
            ddlDay2.Visible = false;
            ddlMonth2.Visible = false;
            ddlYear2.Visible = false;
            ddlYear1.Items.Clear();
            ddlYear2.Items.Clear();

            int _cryr = CE.Global.General.GetUTCDateTime().Year;
            int _styr = 2010;
            for (int _year = _cryr; _year >= _styr; _year--)
            {
                ddlYear1.Items.Add(new ListItem(_year.ToString(), _year.ToString()));
                ddlYear2.Items.Add(new ListItem(_year.ToString(), _year.ToString()));
            }

            ddlDay1.Text = CE.Global.General.GetUTCDateTime().Day.ToString("00");
            ddlMonth1.Text = CE.Global.General.GetUTCDateTime().Month.ToString("00");
            ddlYear1.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000");
            ddlDay2.Text = CE.Global.General.GetUTCDateTime().Day.ToString("00");
            ddlMonth2.Text = CE.Global.General.GetUTCDateTime().Month.ToString("00");
            ddlYear2.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000");
            LoadInsurerList();
            ddlReportType_SelectedIndexChanged(null, null);
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        lblError.Text = "";
        txtReportType.Text = ddlReportType.Text;
        LoadGrid();
    }

    protected void btnDownLoad_Click(object sender, EventArgs e)
    {
        if (grvTescoSummary.Rows.Count > 0)
        {
            string _strDateRange = "Date";
            string _ReportType = "";
            string _strDate1 = txtReportDate1.Text;
            string _strDate2 = txtReportDate2.Text;
            string _Date = "";
            string _FileName = "TescoSummary@";
           
            _ReportType = "";
            if (ddlReportType.Text == "0")
            {
                _ReportType = "Monthly";
                _Date = ": " + GetMonth(_strDate1.Substring(4, 2).ToString());
                _Date += " " + _strDate1.Substring(0, 4).ToString();

                _FileName += GetMonth(_strDate1.Substring(4, 2).ToString()).Trim() + _strDate1.Substring(0, 4).ToString();
            }
            else if (ddlReportType.Text == "1")
            {
                _ReportType = "Daily";
                _Date = " : " + _strDate1.Substring(6, 2).ToString();
                _Date += " " + GetMonth(_strDate1.Substring(4, 2).ToString());
                _Date += " " + _strDate1.Substring(0, 4).ToString();

                _FileName += _strDate1.Substring(6, 2).ToString() + GetMonth(_strDate1.Substring(4, 2).ToString()).Trim() + _strDate1.Substring(0, 4).ToString();
            }
            else if (ddlReportType.Text == "2")
            {
                _ReportType = "Customize";
                _Date = " : " + _strDate1.Substring(6, 2).ToString();
                _Date += " " + GetMonth(_strDate1.Substring(4, 2).ToString());
                _Date += " " + _strDate1.Substring(0, 4).ToString();
                _Date += " TO " + _strDate2.Substring(6, 2).ToString();
                _Date += " " + GetMonth(_strDate2.Substring(4, 2).ToString());
                _Date += " " + _strDate2.Substring(0, 4).ToString();

                _FileName += _strDate1.Substring(6, 2).ToString() + GetMonth(_strDate1.Substring(4, 2).ToString()).Trim() + _strDate1.Substring(0, 4).ToString();
            }
            else if (ddlReportType.Text == "3")
            {
                _ReportType = "Monthly - 1st Half";
                _Date = ": " + GetMonth(_strDate1.Substring(4, 2).ToString());
                _Date += " " + _strDate1.Substring(0, 4).ToString();

                _FileName += GetMonth(_strDate1.Substring(4, 2).ToString()).Trim() + _strDate1.Substring(0, 4).ToString();
            }
            else if (ddlReportType.Text == "4")
            {
                _ReportType = "Monthly - 2nd Half";
                _Date = ": " + GetMonth(_strDate1.Substring(4, 2).ToString());
                _Date += " " + _strDate1.Substring(0, 4).ToString();

                _FileName += GetMonth(_strDate1.Substring(4, 2).ToString()).Trim() + _strDate1.Substring(0, 4).ToString();
            }
            string Campaign = "Online";
            if (ddlCampaign.Text == "1001")
            {
                Campaign = "Offline";
            }
            string Tesco = "All";
            if (ddlTesco.Text == "0")
            {
                Tesco = "N/A";
            }
            else if (ddlTesco.Text == "1")
            {
                Tesco = "Voucher";
            }
            else if (ddlTesco.Text == "2")
            {
                Tesco = "Cash";
            }
           
            _strDateRange = "<tr><td>Report Type</td><td colspan='8'>: " + _ReportType + "</td></tr><tr><td>Statement Date</td><td align='left' colspan='8'>" + _Date + "</td></tr>";

            string strHeader = "<meta http-equiv='content-type' content='text/html; charset=UTF-8'>";
            strHeader += "<table><tr><td colspan='8'><h3>Tesco Sales Report</h3></td>";
            strHeader += "<td style='color:white'>" + CE.Global.General.GetUTCDateTime() + "</td></tr>";
            strHeader += "<tr><td>Insurer</td><td colspan='8'>: " + CE.Global.General.GetProviderName(ddlProvider.Text) + "</td></tr>";
            strHeader += _strDateRange;
            strHeader += "<tr><td>Campaign</td><td colspan='8'>: " + Campaign + "</td></tr>";
            strHeader += "<tr><td>Tesco</td><td colspan='8'>: " + Tesco + "</td></tr>";
            strHeader += "<tr><td>Record Count</td><td colspan='8'>: " + lblRecordCount.Text + "</td></tr>";
            strHeader += "</table>";

            ExportGridView(_FileName, grvTescoSummary, strHeader);
        }
    }

    protected void btnDailyTracker_Click(object sender, EventArgs e)
    {
        try
        {
            //GenerateDailyTracker();
            GenerateDailyInput();
        }
        catch (Exception ex)
        {
        }
    }

    protected void ddlReportType_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblError.Text = "";
        ddlDay1.Text = CE.Global.General.GetUTCDateTime().Day.ToString("00");
        ddlDay2.Text = CE.Global.General.GetUTCDateTime().Day.ToString("00");
        ddlMonth1.Text = CE.Global.General.GetUTCDateTime().Month.ToString("00");
        ddlMonth2.Text = CE.Global.General.GetUTCDateTime().Month.ToString("00");
        ddlYear1.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000");
        ddlYear2.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000");
        if (Convert.ToInt16(ddlReportType.Text) == 0)
        {
            ddlDay1.Visible = false;
            lblFromDate.Text = "Date :";
            lblToDate.Visible = false;
            ddlDay2.Visible = false;
            ddlMonth2.Visible = false;
            ddlYear2.Visible = false;
        }
        else if (Convert.ToInt16(ddlReportType.Text) == 1)
        {
            ddlDay1.Visible = true;
            lblFromDate.Text = "Date :";
            lblToDate.Visible = false;
            ddlDay2.Visible = false;
            ddlMonth2.Visible = false;
            ddlYear2.Visible = false;
        }
        else if (Convert.ToInt16(ddlReportType.Text) == 2)
        {
            lblFromDate.Text = "From Date :";
            lblToDate.Text = " To Date :";
            lblToDate.Visible = true;
            ddlDay2.Visible = true;
            ddlMonth2.Visible = true;
            ddlYear2.Visible = true;
            ddlDay1.Visible = true;
        }
        else if (Convert.ToInt16(ddlReportType.Text) == 3)
        {
            ddlDay1.Visible = false;
            lblFromDate.Text = "Date :";
            lblToDate.Visible = false;
            ddlDay2.Visible = false;
            ddlMonth2.Visible = false;
            ddlYear2.Visible = false;
        }
        else if (Convert.ToInt16(ddlReportType.Text) == 4)
        {
            ddlDay1.Visible = false;
            lblFromDate.Text = "Date :";
            lblToDate.Visible = false;
            ddlDay2.Visible = false;
            ddlMonth2.Visible = false;
            ddlYear2.Visible = false;
        }
    }

    public bool ValidDate(Int32 Year, Int32 Month, Int32 Day)
    {
        bool _isValid = true;
        int daysInMonth = 0;
        string leap, monthValid, dayValid, yearValid;
        if (Year >= 0000)
        {
            yearValid = "yes";
        }
        else
        {
            yearValid = "no";
        }
        if (Year % 400 == 0)
        {
            leap = "yes";
        }
        else if (Year % 100 == 0)
        {
            leap = "no";
        }
        else if (Year % 4 == 0)
        {
            leap = "yes";
        }
        else
        {
            leap = "no";
        }

        switch (Month)
        {
            case 1: daysInMonth = 31;
                break;
            case 3: daysInMonth = 31;
                break;
            case 4: daysInMonth = 30;
                break;
            case 5: daysInMonth = 31;
                break;
            case 6: daysInMonth = 30;
                break;
            case 7: daysInMonth = 31;
                break;
            case 8: daysInMonth = 31;
                break;
            case 9: daysInMonth = 30;
                break;
            case 10: daysInMonth = 31;
                break;
            case 11: daysInMonth = 30;
                break;
            case 12: daysInMonth = 31;
                break;
        }

        if (Month >= 1 && Month <= 12)
        {
            monthValid = "yes";
        }
        else
        {
            monthValid = "no";
        }
        if (Month == 2)
        {
            if (leap == "no")
            {
                daysInMonth = 28;
            }
            else if (leap == "yes")
            {
                daysInMonth = 29;
            }
        }

        if (1 <= Day && Day <= daysInMonth)
        {
            dayValid = "yes";
        }

        else
        {
            dayValid = "no";
        }

        if ((dayValid == "yes") && (monthValid == "yes") && (yearValid == "yes"))
        {
            _isValid = true;
        }
        else
        {
            _isValid = false;
        }

        return _isValid;
    }

    public string GetMonth(string month)
    {
        string result = "";
        if (month == "01")
        {
            result = " Jan ";
        }
        else if (month == "02")
        {
            result = " Feb ";
        }
        else if (month == "03")
        {
            result = " Mar ";
        }
        else if (month == "04")
        {
            result = " Apr ";
        }
        else if (month == "05")
        {
            result = " May ";
        }
        else if (month == "06")
        {
            result = " Jun ";
        }
        else if (month == "07")
        {
            result = " Jul ";
        }
        else if (month == "08")
        {
            result = " Aug ";
        }
        else if (month == "09")
        {
            result = " Sep ";
        }
        else if (month == "10")
        {
            result = " Oct ";
        }
        else if (month == "11")
        {
            result = " Nov ";
        }
        else if (month == "12")
        {
            result = " Dec ";
        }
        return result;
    }

    public string LastDayOfMonth(string ReportDate)
    {
        string result = "31";
        DateTime dtReportDate = Convert.ToDateTime(ReportDate);
        DateTime today = dtReportDate;
        DateTime endOfMonth = new DateTime(today.Year, today.Month, DateTime.DaysInMonth(today.Year, today.Month));
        result = endOfMonth.Day.ToString("00");
        return result;
    }

    public bool Validatioin()
    {
        lblError.Text = "";
        bool _isValid = true;
        DateTime _fromDate, _toDate;
        if (Convert.ToInt16(ddlReportType.Text) == 1)
        {
            if (ddlDay1.SelectedIndex >= 0)
            {
                if (ValidDate(Convert.ToInt32(ddlYear1.Text), Convert.ToInt32(ddlMonth1.Text), Convert.ToInt32(ddlDay1.Text)))
                {
                    _fromDate = Convert.ToDateTime(Convert.ToInt32(ddlYear1.Text) + "/" + Convert.ToInt32(ddlMonth1.Text) + "/" + Convert.ToInt32(ddlDay1.Text));
                    if (_fromDate > CE.Global.General.GetUTCDateTime())
                    {
                        _isValid = false;
                        lblError.Text = "Date should be less than or equal to Today";
                    }
                }
                else
                {
                    _isValid = false;
                    lblError.Text = "Select Valid Date";
                }
            }
            else
            {
                _isValid = false;
                lblError.Text = "Select Date";
            }
        }
        else if (Convert.ToInt16(ddlReportType.Text) == 2)
        {
            if (ddlDay1.SelectedIndex >= 0 && ddlDay2.SelectedIndex >= 0)
            {
                if (ValidDate(Convert.ToInt32(ddlYear1.Text), Convert.ToInt32(ddlMonth1.Text), Convert.ToInt32(ddlDay1.Text)))
                {
                    _fromDate = Convert.ToDateTime(Convert.ToInt32(ddlYear1.Text) + "/" + Convert.ToInt32(ddlMonth1.Text) + "/" + Convert.ToInt32(ddlDay1.Text));
                    if (ValidDate(Convert.ToInt32(ddlYear2.Text), Convert.ToInt32(ddlMonth2.Text), Convert.ToInt32(ddlDay2.Text)))
                    {
                        _toDate = Convert.ToDateTime(Convert.ToInt32(ddlYear2.Text) + "/" + Convert.ToInt32(ddlMonth2.Text) + "/" + Convert.ToInt32(ddlDay2.Text));
                        if (_fromDate <= CE.Global.General.GetUTCDateTime())
                        {
                            if (_fromDate > _toDate)
                            {
                                _isValid = false;
                                lblError.Text = "From date should be less than To date";
                            }
                        }
                        else
                        {
                            _isValid = false;
                            lblError.Text = "From date should be less than Today";
                        }
                    }
                    else
                    {
                        _isValid = false;
                        lblError.Text = "Select Valid To date";
                    }
                }
                else
                {
                    _isValid = false;
                    lblError.Text = "Select Valid From date";
                }
            }
            else
            {
                _isValid = false;
                lblError.Text = "Select From date and To date";
            }
        }
        return _isValid;
    }

    public void LoadGrid()
    {
        lblError.Text = "";
        if (Validatioin() == true)
        {
            txtReportDate1.Text = "";
            txtReportDate2.Text = CE.Global.General.GetUTCDateTime().Year.ToString("0000") + CE.Global.General.GetUTCDateTime().Month.ToString("00") + CE.Global.General.GetUTCDateTime().Day.ToString("00");
            txtReportDate1.Text = ddlYear1.Text;
            txtReportDate1.Text += ddlMonth1.Text;
            txtReportDate1.Text += ddlDay1.Text;
            if (Convert.ToInt16(ddlReportType.Text) == 2)
            {
                txtReportDate2.Text = "";
                txtReportDate2.Text = ddlYear2.Text;
                txtReportDate2.Text += ddlMonth2.Text;
                txtReportDate2.Text += ddlDay2.Text;
            }
            if (Convert.ToInt16(ddlReportType.Text) == 3)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;
                txtReportDate1.Text += "01";
            }
            if (Convert.ToInt16(ddlReportType.Text) == 4)
            {
                txtReportDate1.Text = "";
                txtReportDate1.Text = ddlYear1.Text;
                txtReportDate1.Text += ddlMonth1.Text;
                txtReportDate1.Text += "16";
            }
            DataSet _dsSummary = new DataSet();
            DataTable _dtSummary = new DataTable();
            Int16 _ReportType = Convert.ToInt16(ddlReportType.Text);
            string _ReportDate1 = txtReportDate1.Text.Trim();
            string _ReportDate2 = txtReportDate2.Text.Trim();

            MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
            string _spName = "[sprocReportsCXCRMTescoSummarySelectedList]";
            SortedList _sPara = new SortedList();

            _sPara.Add("@ReportType", _ReportType);
            _sPara.Add("@ReportDate1", _ReportDate1);
            _sPara.Add("@ReportDate2", _ReportDate2);
            _sPara.Add("@TescoId", Convert.ToInt32(ddlTesco.Text));
            _sPara.Add("@Insurer", Convert.ToInt64(ddlProvider.Text));
            _sPara.Add("@UserTypeId", Convert.ToInt32(ddlCampaign.Text));

            _dsSummary = _db.GetDataSet(_spName, _sPara);
            if (_dsSummary != null && _dsSummary.Tables.Count > 0 && _dsSummary.Tables[0].Rows.Count > 0)
            {
                _dtSummary = _dsSummary.Tables[0];
                grvTescoSummary.DataSource = _dtSummary;
                grvTescoSummary.DataBind();
                EnablePrintView();
            }
            else
            {
                grvTescoSummary.DataSource = null;
                grvTescoSummary.DataBind();
                EnablePrintView();
            }
        }
        else
        {
            grvTescoSummary.DataSource = null;
            grvTescoSummary.DataBind();
            EnablePrintView();
        }
    }

    private void EnablePrintView()
    {
        if (grvTescoSummary.Rows.Count > 0)
        {
            //ddlLanguage.Visible = true;
            btnDownLoad.Visible = true;
            lblRecordCount.Text = "(" + grvTescoSummary.Rows.Count.ToString() + ") record(s). Date/Time: " + CE.Global.General.GetUTCDateTime().ToString("dd-MMM-yyyy hh:mm tt") + "&nbsp;&nbsp;";
        }
        else
        {
            //ddlLanguage.Visible = false;
            btnDownLoad.Visible = false;
            lblRecordCount.Text = "";
        }
    }

    public void ExportGridView(string fileName, GridView gvExport, string headerText)
    {
        string attachment = "attachment; filename=" + fileName + ".xls";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        // Create a form to contain the grid
        HtmlForm frm = new HtmlForm();
        frm.InnerHtml = headerText;
        gvExport.Parent.Controls.Add(frm);
        frm.Attributes["runat"] = "server";
        frm.Controls.Add(gvExport);
        frm.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.End();
    }

    public string GetReportMonth(string ReportMonth)
    {
        string month = ReportMonth.Substring(4, 2);
        string year = ReportMonth.Substring(0, 4);
        string result = "";
        if (month == "01")
        {
            result = " Jan ";
        }
        else if (month == "02")
        {
            result = " Feb ";
        }
        else if (month == "03")
        {
            result = " Mar ";
        }
        else if (month == "04")
        {
            result = " Apr ";
        }
        else if (month == "05")
        {
            result = " May ";
        }
        else if (month == "06")
        {
            result = " Jun ";
        }
        else if (month == "07")
        {
            result = " Jul ";
        }
        else if (month == "08")
        {
            result = " Aug ";
        }
        else if (month == "09")
        {
            result = " Sep ";
        }
        else if (month == "10")
        {
            result = " Oct ";
        }
        else if (month == "11")
        {
            result = " Nov ";
        }
        else if (month == "12")
        {
            result = " Dec ";
        }
        return result + year;
    }

    private string GetProvider(Int64 ProviderCompanyId)
    {
        string _result = "";
        if (ProviderCompanyId == 11)
        {
            _result = "AZCP";
        }
        else if (ProviderCompanyId == 12)
        {
            _result = "MSIG";
        }
        else if (ProviderCompanyId == 16)
        {
            _result = "AXA";
        }
        else if (ProviderCompanyId == 29)
        {
            _result = "LMG";
        }
        else if (ProviderCompanyId == 31)
        {
            _result = "CTS";
        }
        else if (ProviderCompanyId == 32)
        {
            _result = "BKI";
        }
        else if (ProviderCompanyId == 33)
        {
            _result = "MTI";
        }
        else if (ProviderCompanyId == 35)
        {
            _result = "KPI";
        }
        else if (ProviderCompanyId == 39)
        {
            _result = "MIR";
        }
        else if (ProviderCompanyId == 41)
        {
            _result = "KSK";// _result = "KUR";
        }
        else if (ProviderCompanyId == 43)
        {
            _result = "SMK";
        }
        else if (ProviderCompanyId == 45)
        {
            _result = "VRY";
        }
        else if (ProviderCompanyId == 46)
        {
            _result = "TMS";
        }
        else if (ProviderCompanyId == 50)
        {
            _result = "SCS";
        }
        else if (ProviderCompanyId == 58)
        {
            _result = "TVV";
        }
        return _result;
    }

    private void CheckPageAccess()
    {
        Int64 PageAccess = General.GetPageAccess(Convert.ToInt64(Session[General.UserId].ToString()), PageCode);
        if (PageAccess == 0)
        {
            Response.Redirect("~/UserMessage.aspx?menu=0&mt=UM&ec=101");
        }
        else
        {
            EnablePageAccess(PageAccess);
        }
    }

    private void EnablePageAccess(Int64 PageAccess)
    {
        if (PageAccess == 100)
        {
            btnDownLoad.Enabled = false;
        }
        else if (PageAccess == 200)
        {
            btnDownLoad.Enabled = true;
        }
    }

    private void LoadInsurerList()
    {
        try
        {
            MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
            DataTable _dt = new DataTable("tblInsurer");
            string _spName = "sprocReportsProviderCompanySelectedList";

            _dt = _db.GetDataTable(_spName);
            ddlProvider.Items.Clear();
            if (_dt != null && _dt.Rows.Count > 0)
            {
                ddlProvider.DataSource = _dt;
                ddlProvider.DataTextField = "CompanyName";
                ddlProvider.DataValueField = "ProviderCompanyId";
                ddlProvider.DataBind();
                ddlProvider.Items.Insert(0, new ListItem("All", "0"));
            }
        }
        catch (Exception Ex)
        {
        }
    }

    public static string GetProviderName(Int64 ProviderCompanyId, string Language)
    {
        string _result = "";
        if (Language == "1")
        {
            if (ProviderCompanyId == 11)
            {
                _result = "อลิอันซ์ ซี.พี. ประกันภัย";
            }
            else if (ProviderCompanyId == 12)
            {
                _result = "เอ็ม เอส ไอ จี ประกันภัย";
            }
            else if (ProviderCompanyId == 16)
            {
                _result = "แอกซ่า ประกันภัย";
            }
            else if (ProviderCompanyId == 29)
            {
                _result = "แอลเอ็มจี ประกันภัย";
            }
            else if (ProviderCompanyId == 31)
            {
                _result = "นิวแฮมพ์เชอร์ อินชัวรันส์";
            }
            else if (ProviderCompanyId == 32)
            {
                _result = "กรุงเทพประกันภัย";
            }
            else if (ProviderCompanyId == 33)
            {
                _result = "เมืองไทยประกันภัย";
            }
            else if (ProviderCompanyId == 35)
            {
                _result = "กรุงไทยพานิชประกันภัย";
            }
            else if (ProviderCompanyId == 39)
            {
                _result = "มิตรแท้ประกันภัย";
            }
            else if (ProviderCompanyId == 41)
            {
                _result = "เค เอส เค";// "คูเนีย ประกันภัย";
            }
            else if (ProviderCompanyId == 43)
            {
                _result = "สินมั่นคงประกันภัย";
            }
            else if (ProviderCompanyId == 45)
            {
                _result = "วิริยะประกันภัย";
            }
            else if (ProviderCompanyId == 46)
            {
                _result = "โตเกียวมารีนศรีเมือง";
            }
            else if (ProviderCompanyId == 50)
            {
                _result = "ไทยพาณิชย์สามัคคีประกันภัย";
            }
            else if (ProviderCompanyId == 58)
            {
                _result = "ประกันภัยไทยวิวัฒน์";
            }

        }
        else if (Language == "2")
        {
            if (ProviderCompanyId == 11)
            {
                _result = "Allianz CP Insurance";
            }
            else if (ProviderCompanyId == 12)
            {
                _result = "MSIG Insurance";
            }
            else if (ProviderCompanyId == 16)
            {
                _result = "AXA Insurance";
            }
            else if (ProviderCompanyId == 29)
            {
                _result = "LMG  Insurance";
            }
            else if (ProviderCompanyId == 31)
            {
                _result = "Chartis Insurance";
            }
            else if (ProviderCompanyId == 32)
            {
                _result = "BKI Insurance";
            }
            else if (ProviderCompanyId == 33)
            {
                _result = "MuangThai Insurance";
            }
            else if (ProviderCompanyId == 35)
            {
                _result = "KrungThai Insurance";
            }
            else if (ProviderCompanyId == 39)
            {
                _result = "Mittare Insurance";
            }
            else if (ProviderCompanyId == 41)
            {
                _result = "KSK Insurance";
            }
            else if (ProviderCompanyId == 43)
            {
                _result = "Synmunkong Insurance";
            }
            else if (ProviderCompanyId == 45)
            {
                _result = "Viriyah Insurance";
            }
            else if (ProviderCompanyId == 46)
            {
                _result = "Tokio Marine Insurance";
            }
            else if (ProviderCompanyId == 50)
            {
                _result = "SCSMG Insurance";
            }
            else if (ProviderCompanyId == 58)
            {
                _result = "Thaivivat Insurance";
            }
        }
        return _result;
    }

    public void GenerateDailyTracker()
    {
        string _htmlDT = "";
        string _fileName = "DailyTracker@" + CE.Global.General.GetUTCDateTime().Day.ToString("00") + "-" + CE.Global.General.GetUTCDateTime().Month.ToString("00") + "-" + CE.Global.General.GetUTCDateTime().Year;
        Label lblContent = new Label();
        lblContent.Text = "";
 
        txtReportDate1.Text = "";
        txtReportDate1.Text = ddlYear1.Text;
        txtReportDate1.Text += ddlMonth1.Text;
        txtReportDate1.Text += ddlDay1.Text;
       
        string _ReportDate = txtReportDate1.Text.Trim();
        Int32 _UserTypeId = Convert.ToInt32(ddlCampaign.Text);
        
        MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
        string _spName = "[sprocReportsGGDailyTrackersSelectedItemList]";
        SortedList _sPara = new SortedList();
        _sPara.Add("@ReportDate", _ReportDate);

        Int32 TotalFileCount = 0;
        DataSet _dsSummary = new DataSet();
        _dsSummary = _db.GetDataSet(_spName, _sPara);
        if (_dsSummary != null && _dsSummary.Tables.Count > 0 && _dsSummary.Tables[0].Rows.Count > 0)
        {
            TotalFileCount += _dsSummary.Tables[0].Rows.Count;
        }
        if (TotalFileCount > 0)
        {
            _spName = "[sprocReportsGGDailyTrackersWorkingDaysCount]";
            SortedList _sParam = new SortedList();
            _sParam.Add("@ReportDate", _ReportDate);
            DataSet _dsWorkDays = new DataSet();
            _dsWorkDays = _db.GetDataSet(_spName, _sParam);

            #region Variable Declaration
            string[] _strTitle = new string[TotalFileCount];
            DateTime _dDate = CE.Global.General.GetUTCDateTime();
            string _strCampaignName, _strReportMonth, _strReportDate, _strYear, _strMonth;
            Int32 _intMAvailTotal, _intYAvailTotal, _intMAvailNew, _intYAvailNew, _intMAvailOld, _intYAvailOld, _intMRClosed, _intYRClosed;
            Int32 _intMEffContact, _intYEffContact, _intMContactRate, _intYContactRate, _intMSalesPolicies, _intYSalesPolicies;
            Int32 _intNoOfWorkingDay, _intNoOfWorkingDayComplete, _intNoOfWorkingDayLeft;
            decimal _decMConverRate, _decYConverRate, _decMANPPerPolicy, _decYANPPerPolicy, _decMANP, _decYANP, _decMPenetrRate, _decYPenetrRate;

            _strCampaignName = "GluayGluay.com"; _strReportMonth = ""; _strReportDate = ""; _strYear = ""; _strMonth = "";
            _intMAvailTotal = 0; _intYAvailTotal = 0; _intMAvailNew = 0; _intYAvailNew = 0; _intMAvailOld = 0; _intYAvailOld = 0;
            _intMRClosed = 0; _intYRClosed = 0; _intMEffContact = 0; _intYEffContact = 0; _intMContactRate = 0; _intYContactRate = 0;
            _intMSalesPolicies = 0; _intYSalesPolicies = 0; _intNoOfWorkingDay = 0; _intNoOfWorkingDayComplete = 0; _intNoOfWorkingDayLeft = 0; 
            _decMConverRate = 0; _decYConverRate = 0; _decMANPPerPolicy = 0; _decYANPPerPolicy = 0; _decMANP = 0; _decYANP = 0; 
            _decMPenetrRate = 0; _decYPenetrRate = 0;
            //string[] RecordsAvailable = new string[4];
            //string[] RecordsAvailableNew = new string[4];
            //string[] RecordsAvailableOld = new string[4];
            //string[] RecordsClosed = new string[4];
            //string[] EffectiveContact = new string[4];
            //string[] ContactRate = new string[4];
            //string[] MESigninHours = new string[4];
            //string[] SalesRecord = new string[4];
            //string[] SalesPolicies = new string[4];
            //string[] SalesRecordPerHour = new string[4];
            //string[] SalesPoliciesPerHour = new string[4];
            //string[] MonthlyPremiumPerHour = new string[4];
            //string[] EffectiveContactPerHour = new string[4];
            //string[] ConversionRateSales = new string[4];
            //string[] ConversionRatePolicies = new string[4];
            //string[] ANPPerSale = new string[4];
            //string[] ANPPerPolicy = new string[4];
            //string[] ANP = new string[4];
            //string[] PenetrationRateSales = new string[4];
            //string[] PenetrationRatePolicies = new string[4];

           #endregion

            #region Value Assign
            if (_dsWorkDays != null && _dsWorkDays.Tables.Count > 0 && _dsWorkDays.Tables[0].Rows.Count > 0)
            {
                if (_dsWorkDays.Tables[0].Rows[0]["NoofWorkDays"].ToString() == string.Empty ||
                    (!Int32.TryParse(_dsWorkDays.Tables[0].Rows[0]["NoofWorkDays"].ToString(), out _intNoOfWorkingDay)))
                {
                    _intNoOfWorkingDay = 0;
                }
                if (_dsWorkDays.Tables[0].Rows[0]["NoofComplete"].ToString() == string.Empty ||
                    (!Int32.TryParse(_dsWorkDays.Tables[0].Rows[0]["NoofComplete"].ToString(), out _intNoOfWorkingDayComplete)))
                {
                    _intNoOfWorkingDayComplete = 0;
                }
                if (_dsWorkDays.Tables[0].Rows[0]["NoofLeft"].ToString() == string.Empty ||
                    (!Int32.TryParse(_dsWorkDays.Tables[0].Rows[0]["NoofLeft"].ToString(), out _intNoOfWorkingDayLeft)))
                {
                    _intNoOfWorkingDayLeft = 0;
                }
            }
            if (!DateTime.TryParse(_dsSummary.Tables[0].Rows[0]["ReportMonth"].ToString(), out _dDate))
            {
                _dDate = CE.Global.General.GetUTCDateTime();
            }
            for (int i = 0; i < TotalFileCount; i++)
            {
                _strTitle[i] = _dsSummary.Tables[0].Rows[i]["Description"].ToString();
            }

            if (_dsSummary.Tables[0].Rows[0]["MonthlyActual"].ToString() == string.Empty ||
                (!Int32.TryParse(_dsSummary.Tables[0].Rows[0]["MonthlyActual"].ToString(), out _intMAvailTotal)))
            {
                _intMAvailTotal = 0;
            }
            if (_dsSummary.Tables[0].Rows[0]["YearlyActual"].ToString() == string.Empty ||
                (!Int32.TryParse(_dsSummary.Tables[0].Rows[0]["YearlyActual"].ToString(), out _intYAvailTotal)))
            {
                _intYAvailTotal = 0;
            }
            if (_dsSummary.Tables[0].Rows[1]["MonthlyActual"].ToString() == string.Empty ||
                (!Int32.TryParse(_dsSummary.Tables[0].Rows[1]["MonthlyActual"].ToString(), out _intMAvailNew)))
            {
                _intMAvailNew = 0;
            }
            if (_dsSummary.Tables[0].Rows[1]["YearlyActual"].ToString() == string.Empty ||
                (!Int32.TryParse(_dsSummary.Tables[0].Rows[1]["YearlyActual"].ToString(), out _intYAvailNew)))
            {
                _intYAvailNew = 0;
            }
            if (_dsSummary.Tables[0].Rows[2]["MonthlyActual"].ToString() == string.Empty ||
                (!Int32.TryParse(_dsSummary.Tables[0].Rows[2]["MonthlyActual"].ToString(), out _intMAvailOld)))
            {
                _intMAvailOld = 0;
            }
            if (_dsSummary.Tables[0].Rows[2]["YearlyActual"].ToString() == string.Empty ||
                (!Int32.TryParse(_dsSummary.Tables[0].Rows[2]["YearlyActual"].ToString(), out _intYAvailOld)))
            {
                _intYAvailOld = 0;
             }
             if (_dsSummary.Tables[0].Rows[3]["MonthlyActual"].ToString() == string.Empty ||
                (!Int32.TryParse(_dsSummary.Tables[0].Rows[3]["MonthlyActual"].ToString(), out _intMRClosed)))
            {
                _intMRClosed = 0;
            }
             if (_dsSummary.Tables[0].Rows[3]["YearlyActual"].ToString() == string.Empty ||
                (!Int32.TryParse(_dsSummary.Tables[0].Rows[3]["YearlyActual"].ToString(), out _intYRClosed)))
            {
                _intYRClosed = 0;
            }
            if (_dsSummary.Tables[0].Rows[4]["MonthlyActual"].ToString() == string.Empty ||
                (!Int32.TryParse(_dsSummary.Tables[0].Rows[4]["MonthlyActual"].ToString(), out _intMEffContact)))
            {
                _intMEffContact = 0;
            }
            if (_dsSummary.Tables[0].Rows[4]["YearlyActual"].ToString() == string.Empty ||
                (!Int32.TryParse(_dsSummary.Tables[0].Rows[4]["YearlyActual"].ToString(), out _intYEffContact)))
            {
                _intYEffContact = 0;
            }
            if (_dsSummary.Tables[0].Rows[5]["MonthlyActual"].ToString() == string.Empty ||
                (!Int32.TryParse(_dsSummary.Tables[0].Rows[5]["MonthlyActual"].ToString(), out _intMContactRate)))
            {
                _intMContactRate = 0;
            }
            if (_dsSummary.Tables[0].Rows[5]["YearlyActual"].ToString() == string.Empty ||
                (!Int32.TryParse(_dsSummary.Tables[0].Rows[5]["YearlyActual"].ToString(), out _intYContactRate)))
            {
                _intYContactRate = 0;
            }
            if (_dsSummary.Tables[0].Rows[8]["MonthlyActual"].ToString() == string.Empty ||
                (!Int32.TryParse(_dsSummary.Tables[0].Rows[8]["MonthlyActual"].ToString(), out _intMSalesPolicies)))
            {
                _intMSalesPolicies = 0;
            }
            if (_dsSummary.Tables[0].Rows[8]["YearlyActual"].ToString() == string.Empty ||
                (!Int32.TryParse(_dsSummary.Tables[0].Rows[8]["YearlyActual"].ToString(), out _intYSalesPolicies)))
            {
                _intYSalesPolicies = 0;
            }

            if (_dsSummary.Tables[0].Rows[14]["MonthlyActual"].ToString() == string.Empty ||
                (!decimal.TryParse(_dsSummary.Tables[0].Rows[14]["MonthlyActual"].ToString(), out _decMConverRate)))
            {
                _decMConverRate = 0;
            }
            if (_dsSummary.Tables[0].Rows[14]["YearlyActual"].ToString() == string.Empty ||
                (!decimal.TryParse(_dsSummary.Tables[0].Rows[14]["YearlyActual"].ToString(), out _decYConverRate)))
            {
                _decYConverRate = 0;
            }
            if (_dsSummary.Tables[0].Rows[16]["MonthlyActual"].ToString() == string.Empty ||
                (!decimal.TryParse(_dsSummary.Tables[0].Rows[16]["MonthlyActual"].ToString(), out _decMANPPerPolicy)))
            {
                _decMANPPerPolicy = 0;
            }
            if (_dsSummary.Tables[0].Rows[16]["YearlyActual"].ToString() == string.Empty ||
                (!decimal.TryParse(_dsSummary.Tables[0].Rows[16]["YearlyActual"].ToString(), out _decYANPPerPolicy)))
            {
                _decYANPPerPolicy = 0;
            }
            if (_dsSummary.Tables[0].Rows[17]["MonthlyActual"].ToString() == string.Empty ||
                (!decimal.TryParse(_dsSummary.Tables[0].Rows[17]["MonthlyActual"].ToString(), out _decMANP)))
            {
                _decMANP = 0;
            }
            if (_dsSummary.Tables[0].Rows[17]["YearlyActual"].ToString() == string.Empty ||
                (!decimal.TryParse(_dsSummary.Tables[0].Rows[17]["YearlyActual"].ToString(), out _decYANP)))
            {
                _decYANP = 0;
            }
            if (_dsSummary.Tables[0].Rows[19]["MonthlyActual"].ToString() == string.Empty ||
                (!decimal.TryParse(_dsSummary.Tables[0].Rows[19]["MonthlyActual"].ToString(), out _decMPenetrRate)))
            {
                _decMPenetrRate = 0;
            }
            if (_dsSummary.Tables[0].Rows[19]["YearlyActual"].ToString() == string.Empty ||
                (!decimal.TryParse(_dsSummary.Tables[0].Rows[19]["YearlyActual"].ToString(), out _decYPenetrRate)))
            {
                _decYPenetrRate = 0;
            }

            _strReportMonth = _dDate.ToString("MMMM-yyyy");
            _strReportDate = _dDate.ToString("dd-MMM-yyyy");
            _strYear = _dDate.ToString("yyyy");
            _strMonth = _dDate.ToString("MMM-yy");
            #endregion

            #region Generate Excel
            _strReportMonth = GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text;
            _strReportDate = ddlDay1.Text + " " + GetMonth(ddlMonth1.Text).Trim() + " " + ddlYear1.Text;
            _htmlDT += "<html>";
            _htmlDT += "<head>";
            _htmlDT += "<meta http-equiv='content-type' content='text/html; charset=UTF-8'>";
            _htmlDT += "</head>";
            _htmlDT += "<body>";

            #region Heading
            _htmlDT += "<table width='75%' cellpadding='1' cellspacing='1'>";

            _htmlDT += "<tr><td colspan='8' align='center' style='font-size:16px;'><b>Campaign Daily Tracker</b></td></tr>";
            _htmlDT += "<tr>";
            _htmlDT += "<td colspan='7'>&nbsp;</td>";
            _htmlDT += "<td width='80px'><img src='http://www.gluaygluay.com/management/images/logos/gluaygluay_small.png' alt='gluaygluay' width='50px' height='40px' /></td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td colspan='2' align='left' style='font-size:12px;'><b>Campaign Name :</b></td>";
            _htmlDT += "<td colspan='6' align='left' style='font-size:12px;'><b>GluayGluay.com</b></td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td colspan='2' align='left' style='font-size:12px;'><b>Reporting Month :</b></td>";
            _htmlDT += "<td colspan='6' align='left' style='font-size:12px;'><b>" + _strReportMonth.ToString() + "</b></td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td colspan='2' align='left' style='font-size:12px;'><b>No. of Working days :</b></td>";
            _htmlDT += "<td colspan='6' align='left' style='font-size:12px;'><b>" + _intNoOfWorkingDay.ToString() + "</b></td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td colspan='2' align='left' style='font-size:12px;'><b>No. of Working days completed :</b></td>";
            _htmlDT += "<td colspan='6' align='left' style='font-size:12px;'><b>" + _intNoOfWorkingDayComplete.ToString() + "</b></td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td colspan='2' align='left' style='font-size:12px;'><b>No. of Working days left :</b></td>";
            _htmlDT += "<td colspan='6' align='left' style='font-size:12px;'><b>" + _intNoOfWorkingDayLeft.ToString() + "</b></td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td colspan='2' align='left' style='font-size:12px;'><b>Today :</b></td>";
            _htmlDT += "<td colspan='6' align='left' style='font-size:12px;'><b>" + _strReportDate.ToString() + "</b></td>";
            _htmlDT += "</tr>";

            _htmlDT += "</table>";
            #endregion
            
            _htmlDT += "<table width='100%' cellpadding='1' cellspacing='1'>";
            _htmlDT += "<tr><td colspan='8'>&nbsp;</td></tr>";
            _htmlDT += "</table>";

            #region Body
            _htmlDT += "<table width='75%' cellpadding='1' cellspacing='1' border='1'>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px'>&nbsp;</td>";
            _htmlDT += "<td width='300px'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#0B2161;'><b style='color:#FFFFFF'>Plan</b></td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#0B2161;'><b style='color:#FFFFFF'>Actual</b></td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#0B2161;'><b style='color:#FFFFFF'>Variance (%)</b></td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#0B2161'></td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#0B2161;'><b style='color:#FFFFFF'>Plan</b></td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#0B2161;'><b style='color:#FFFFFF'>Actual</b></td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#0B2161;'><b style='color:#FFFFFF'>Variance (%)</b></td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px'>&nbsp;</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#0B2161;'><b style='color:#FFFFFF'>Description</b></td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#0B2161;'><b style='color:#FFFFFF'>" + _strMonth + "</b></td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#0B2161;'><b style='color:#FFFFFF'>MTD</b></td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#0B2161;'><b style='color:#FFFFFF'>MTD</b></td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#0B2161'></td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#0B2161;'><b style='color:#FFFFFF'>" + _strYear + "</b></td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#0B2161;'><b style='color:#FFFFFF'>YTD</b></td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#0B2161;'><b style='color:#FFFFFF'>YTD</b></td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>1</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[0].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781; mso-number-format:\\#\\,\\#\\#0'>" + _intMAvailTotal.ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781; mso-number-format:\\#\\,\\#\\#0'>" + _intYAvailTotal.ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>&nbsp;</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>a) " + _strTitle[1].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781; mso-number-format:\\#\\,\\#\\#0'>" + _intMAvailNew.ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781; mso-number-format:\\#\\,\\#\\#0'>" + _intYAvailNew.ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>&nbsp;</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>b) " + _strTitle[2].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781; mso-number-format:\\#\\,\\#\\#0'>" + _intMAvailOld.ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781; mso-number-format:\\#\\,\\#\\#0'>" + _intYAvailOld.ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>2</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[3].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781; mso-number-format:\\#\\,\\#\\#0'>" + _intMRClosed.ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781; mso-number-format:\\#\\,\\#\\#0'>" + _intYRClosed.ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>3</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[4].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781; mso-number-format:\\#\\,\\#\\#0'>" + _intMEffContact.ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781; mso-number-format:\\#\\,\\#\\#0'>" + _intYEffContact.ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>4</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[5].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>" + _intMContactRate.ToString() + "%</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>" + _intYContactRate.ToString() + "%</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>5</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[6].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>6</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[7].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>7</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[8].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781; mso-number-format:\\#\\,\\#\\#0'>" + _intMSalesPolicies.ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781; mso-number-format:\\#\\,\\#\\#0'>" + _intYSalesPolicies.ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>8</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[9].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>9</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[10].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>10</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[11].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>11</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[12].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>12</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[13].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>13</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[14].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>" + _decMConverRate.ToString() + "%</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>" + _decYConverRate.ToString() + "%</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>14</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[15].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>15</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[16].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>" + _decMANPPerPolicy.ToString("#0,000.00") + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>" + _decYANPPerPolicy.ToString("#0,000.00") + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>16</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[17].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>" + _decMANP.ToString("#0,000.00") + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>" + _decYANP.ToString("#0,000.00") + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>17</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[18].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "<tr>";
            _htmlDT += "<td width='30px' align='center'>18</td>";
            _htmlDT += "<td align='left' style='width:300px; font-size:12px; background-color:#CECEF6;'>" + _strTitle[19].ToString() + "</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>" + _decMPenetrRate.ToString() + "%</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            //_htmlDT += "<td align='center' style='width:1px; background-color:#F3F781'>&nbsp;</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>" + _decYPenetrRate.ToString() + "%</td>";
            _htmlDT += "<td align='center' style='width:80px; font-size:12px; background-color:#F3F781;'>-</td>";
            _htmlDT += "</tr>";

            _htmlDT += "</table>";
            #endregion

            _htmlDT += "<table width='100%' cellpadding='1' cellspacing='1'>";
            _htmlDT += "<tr><td colspan='8'>&nbsp;</td></tr>";
            _htmlDT += "</table>";

            #region Definitions
            _htmlDT += "<table width='100%' cellpadding='1' cellspacing='1'>";

            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'><b>Definitions :</b></td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>1 <b>Records Available –</b> Remaining records in system for ME to call.</td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>2 <b>Records Closed –</b> Records utilized by ME resulting to effective and ineffective contact that will not be used again for calling.</td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>3 <b>Effective Contact (speak to customer) –</b> A call made to customer with a decision either to purchase or refuse to purchase.</td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>4 <b>Contact Rate –</b> Contactability of the database.</td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>5 <b>ME Sign In Hours –</b> Time taken by ME to complete the database.</td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>6 <b>Sales Record -</b> Number of sales closed.</td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>7 <b>Sales Policies -</b> Number of policies sold.</td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>8 <b>Sales Record Per Hour –</b> Sales Record divided by ME sign in hours.</td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>9 <b>Sales Policies Per Hour -</b>  Sales Policies divided by ME sign in hours.</td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>10 <b>Monthly Premium Per Hour -</b> Monthly Premium generated divided by ME sign in hours.</td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>11 <b>Effective Contact Per Hour –</b> Effective Contact divided by ME sign in hours.</td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>12 <b>Conversion Rate (Sales Record) –</b> Sales Record divided by effective contact.</td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>13 <b>Conversion Rate (Policies) –</b> Sales Policies divided by effective contact.</td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>14 <b>ANP Per Sale (THB) -</b> Average annualized premium generated from a sale. </td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>15 <b>ANP Per Policy (THB) -</b> Average annualized premium generated from a policy.</td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>16 <b>ANP (THB) -</b> Annualized premium generated.</td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>17 <b>Penetration Rate (Sales Record) -</b> Percentage of sales record divided by marketable records.</td></tr>";
            _htmlDT += "<tr><td colspan='8' style='font-size:12px;'>18 <b>Penetration Rate (Sales Policies) -</b> Percentage of sales policies divided by marketable records.</td></tr>";

            _htmlDT += "</table>";
            #endregion

            _htmlDT += "</body>";
            _htmlDT += "</html>";
            #endregion

            lblContent.Text = _htmlDT;
            ExportGridView(_fileName, lblContent);
        }
    }

    public void GenerateDailyInput()
    {
        string _htmlDT = "";
        string _htmlDI = "";
        string _fileName = "";
        Label lblContent = new Label();
        lblContent.Text = "";

        txtReportDate1.Text = "";
        txtReportDate1.Text = ddlYear1.Text;
        txtReportDate1.Text += ddlMonth1.Text;
        txtReportDate1.Text += ddlDay1.Text;

        _fileName = "GG_DailyInput@" + ddlDay1.Text + "-" + ddlMonth1.Text + "-" + ddlYear1.Text;
        string _ReportDate = txtReportDate1.Text.Trim();
        Int32 _UserTypeId = Convert.ToInt32(ddlCampaign.Text);

        MyDatabase _db = new MyDatabase("GGR_DBConnectionString");
        string _spName = "[sprocReportsGGDailyTrackersDailyInputItemList]";
        SortedList _sPara = new SortedList();
        _sPara.Add("@ReportDate", _ReportDate);

        Int32 TotalFileCount = 0;
        DataSet _dsSummary = new DataSet();
        _dsSummary = _db.GetDataSet(_spName, _sPara);
        if (_dsSummary != null && _dsSummary.Tables.Count > 0 && _dsSummary.Tables[0].Rows.Count > 0)
        {
            TotalFileCount += _dsSummary.Tables[0].Rows.Count;
        }
        if (TotalFileCount > 0)
        {            

            #region Variable Declaration
            DateTime _dDate = CE.Global.General.GetUTCDateTime();
            Int32 _intAvailTotal, _intRClosed, _intEffContact, _intSalesPolicies;
            Int32 _intTotalRecAvailable, _intTotalRecClosed, _intTotalEffContact, _intTotalSalesPolicies;
            Int32 _intNoOfWorkingDay, _intNoOfLeft, _intNoOfFinished, _intCount;

            decimal _decContactRate, _decConverRate, _decANPPerPolicy, _decANP, _decPenetrRate;
            decimal _decTotalContactRate, _decTotalConversionRate, _decTotalANPperPolicy, _decTotalANP, _decTotalPenetrationRate;
            
            _intAvailTotal = 0; _intRClosed = 0; _intEffContact = 0; _intSalesPolicies = 0;
            _intTotalRecAvailable = 0; _intTotalRecClosed = 0; _intTotalEffContact = 0; _intTotalSalesPolicies = 0;
            _intNoOfWorkingDay = 0; _intNoOfLeft = 0; _intNoOfFinished = 0; _intCount = 1;

            _decContactRate = 0; _decConverRate = 0; _decANPPerPolicy = 0; _decANP = 0; _decPenetrRate = 0;
            _decTotalContactRate = 0; _decTotalConversionRate = 0; _decTotalANPperPolicy = 0; _decTotalANP = 0; _decTotalPenetrationRate = 0;

            DateTime[] ReportDate = new DateTime[TotalFileCount];
            Int16[] DayType = new Int16[TotalFileCount];
            string[] RecAvailable = new string[TotalFileCount];
            string[] RecClosed = new string[TotalFileCount];
            string[] EffContact = new string[TotalFileCount];
            string[] ContactRate = new string[TotalFileCount];
            string[] SalesPolicies = new string[TotalFileCount];
            decimal[] ConversionRate = new decimal[TotalFileCount];
            string[] ANPperPolicy = new string[TotalFileCount];
            string[] ANP = new string[TotalFileCount];
            decimal[] PenetrationRate = new decimal[TotalFileCount];
            string[] ReminingDays = new string[TotalFileCount];
            #endregion

            #region Values Assign
            if (_dsSummary.Tables.Count > 1 && _dsSummary.Tables[1].Rows.Count > 0)
            {
                if (_dsSummary.Tables[1].Rows[0]["NoofWorkDays"].ToString() == string.Empty ||
                    (!Int32.TryParse(_dsSummary.Tables[1].Rows[0]["NoofWorkDays"].ToString(), out _intNoOfWorkingDay)))
                {
                    _intNoOfWorkingDay = 0;
                }
                if (_dsSummary.Tables[1].Rows[0]["NoofLeft"].ToString() == string.Empty ||
                    (!Int32.TryParse(_dsSummary.Tables[1].Rows[0]["NoofLeft"].ToString(), out _intNoOfLeft)))
                {
                    _intNoOfLeft = 0;
                }
                _intNoOfFinished = (_intNoOfWorkingDay - _intNoOfLeft);

                if (_dsSummary.Tables[1].Rows[0]["TotalRecAvailable"].ToString() == string.Empty ||
                   (!Int32.TryParse(_dsSummary.Tables[1].Rows[0]["TotalRecAvailable"].ToString(), out _intTotalRecAvailable)))
                {
                    _intTotalRecAvailable = 0;
                }
                if (_dsSummary.Tables[1].Rows[0]["TotalRecClosed"].ToString() == string.Empty ||
                  (!Int32.TryParse(_dsSummary.Tables[1].Rows[0]["TotalRecClosed"].ToString(), out _intTotalRecClosed)))
                {
                    _intTotalRecClosed = 0;
                }
                if (_dsSummary.Tables[1].Rows[0]["TotalEffContact"].ToString() == string.Empty ||
                  (!Int32.TryParse(_dsSummary.Tables[1].Rows[0]["TotalEffContact"].ToString(), out _intTotalEffContact)))
                {
                    _intTotalEffContact = 0;
                }
                if (_dsSummary.Tables[1].Rows[0]["TotalSalesPolicies"].ToString() == string.Empty ||
                  (!Int32.TryParse(_dsSummary.Tables[1].Rows[0]["TotalSalesPolicies"].ToString(), out _intTotalSalesPolicies)))
                {
                    _intTotalSalesPolicies = 0;
                }

                if (_dsSummary.Tables[1].Rows[0]["TotalContactRate"].ToString() == string.Empty ||
                  (!decimal.TryParse(_dsSummary.Tables[1].Rows[0]["TotalContactRate"].ToString(), out _decTotalContactRate)))
                {
                    _decTotalContactRate = 0;
                }
                if (_dsSummary.Tables[1].Rows[0]["TotalConversionRate"].ToString() == string.Empty ||
                  (!decimal.TryParse(_dsSummary.Tables[1].Rows[0]["TotalConversionRate"].ToString(), out _decTotalConversionRate)))
                {
                    _decTotalConversionRate = 0;
                }
                if (_dsSummary.Tables[1].Rows[0]["TotalANPperPolicy"].ToString() == string.Empty ||
                  (!decimal.TryParse(_dsSummary.Tables[1].Rows[0]["TotalANPperPolicy"].ToString(), out _decTotalANPperPolicy)))
                {
                    _decTotalANPperPolicy = 0;
                }
                if (_dsSummary.Tables[1].Rows[0]["TotalANP"].ToString() == string.Empty ||
                  (!decimal.TryParse(_dsSummary.Tables[1].Rows[0]["TotalANP"].ToString(), out _decTotalANP)))
                {
                    _decTotalANP = 0;
                }

                for (int i = 0; i < TotalFileCount; i++)
                {
                    Int16 _sintDayType = 0;
                    if (_dsSummary.Tables[0].Rows[i]["DayType"].ToString() == string.Empty ||
                        (!Int16.TryParse(_dsSummary.Tables[0].Rows[i]["DayType"].ToString(), out _sintDayType)))
                    {
                        _sintDayType = 0;
                    }
                    DayType[i] = _sintDayType;
                                        
                    if (_sintDayType == 1)
                    {
                        ReminingDays[i] = (_intNoOfWorkingDay - _intCount).ToString();
                        _intCount += 1;
                    }
                    else
                    {
                        ReminingDays[i] = "0";
                    }

                    DateTime _dtRDate = CE.Global.General.GetUTCDateTime();
                    if (_dsSummary.Tables[0].Rows[i]["ReportDate"].ToString() == string.Empty ||
                        (!DateTime.TryParse(_dsSummary.Tables[0].Rows[i]["ReportDate"].ToString(), out _dtRDate)))
                    {
                        _dtRDate = CE.Global.General.GetUTCDateTime(); 
                    }
                    ReportDate[i] = _dtRDate;

                    if (_dsSummary.Tables[0].Rows[i]["RecAvailable"].ToString() == string.Empty ||
                        (!Int32.TryParse(_dsSummary.Tables[0].Rows[i]["RecAvailable"].ToString(), out _intAvailTotal)))
                    {
                        _intAvailTotal = 0;
                    }
                    RecAvailable[i] = _intAvailTotal.ToString();
                    //_intTotalRecAvailable += _intAvailTotal;

                    if (_dsSummary.Tables[0].Rows[i]["RecClosed"].ToString() == string.Empty ||
                        (!Int32.TryParse(_dsSummary.Tables[0].Rows[i]["RecClosed"].ToString(), out _intRClosed)))
                    {
                        _intRClosed = 0;
                    }
                    RecClosed[i] = _intRClosed.ToString();
                    //_intTotalRecClosed += _intRClosed;

                    if (_dsSummary.Tables[0].Rows[i]["EffContact"].ToString() == string.Empty ||
                        (!Int32.TryParse(_dsSummary.Tables[0].Rows[i]["EffContact"].ToString(), out _intEffContact)))
                    {
                        _intEffContact = 0;
                    }
                    EffContact[i] = _intEffContact.ToString();
                    //_intTotalEffContact += _intEffContact;

                    if (_dsSummary.Tables[0].Rows[i]["ContactRate"].ToString() == string.Empty ||
                        (!decimal.TryParse(_dsSummary.Tables[0].Rows[i]["ContactRate"].ToString(), out _decContactRate)))
                    {
                        _decContactRate = 0;
                    }
                    ContactRate[i] = _decContactRate.ToString();
                    //_decTotalContactRate += _decContactRate;

                    if (_dsSummary.Tables[0].Rows[i]["SalesPolicies"].ToString() == string.Empty ||
                        (!Int32.TryParse(_dsSummary.Tables[0].Rows[i]["SalesPolicies"].ToString(), out _intSalesPolicies)))
                    {
                        _intSalesPolicies = 0;
                    }
                    SalesPolicies[i] = _intSalesPolicies.ToString();
                    //_intTotalSalesPolicies += _intSalesPolicies;

                    if (_dsSummary.Tables[0].Rows[i]["ConversionRate"].ToString() == string.Empty ||
                        (!decimal.TryParse(_dsSummary.Tables[0].Rows[i]["ConversionRate"].ToString(), out _decConverRate)))
                    {
                        _decConverRate = 0;
                    }
                    ConversionRate[i] = _decConverRate;
                    //_decTotalConversionRate += _decConverRate;

                    if (_dsSummary.Tables[0].Rows[i]["ANPperPolicy"].ToString() == string.Empty ||
                        (!decimal.TryParse(_dsSummary.Tables[0].Rows[i]["ANPperPolicy"].ToString(), out _decANPPerPolicy)))
                    {
                        _decANPPerPolicy = 0;
                    }
                    ANPperPolicy[i] = _decANPPerPolicy.ToString();
                    //_decTotalANPperPolicy += _decANPPerPolicy;

                    if (_dsSummary.Tables[0].Rows[i]["ANP"].ToString() == string.Empty ||
                        (!decimal.TryParse(_dsSummary.Tables[0].Rows[i]["ANP"].ToString(), out _decANP)))
                    {
                        _decANP = 0;
                    }
                    ANP[i] = _decANP.ToString();
                    //_decTotalANP += _decANP;

                    if (_dsSummary.Tables[0].Rows[i]["PenetrationRate"].ToString() == string.Empty ||
                        (!decimal.TryParse(_dsSummary.Tables[0].Rows[i]["PenetrationRate"].ToString(), out _decPenetrRate)))
                    {
                        _decPenetrRate = 0;
                    }
                    PenetrationRate[i] = _decPenetrRate;
                    //_decTotalPenetrationRate += _decPenetrRate;
                }
                _decTotalContactRate = Math.Ceiling((Convert.ToDecimal(_intTotalEffContact) * 100) / Convert.ToDecimal(_intTotalRecClosed));
                _decTotalConversionRate = ((Convert.ToDecimal(_intTotalSalesPolicies) * 100) / Convert.ToDecimal(_intTotalEffContact));
                _decTotalPenetrationRate = ((Convert.ToDecimal(_intTotalSalesPolicies) * 100) / Convert.ToDecimal(_intTotalRecClosed));

            }
            #endregion

            #region Generate Excel
            _htmlDI += "<html>";
            _htmlDI += "<head>";
            _htmlDI += "<meta http-equiv='content-type' content='text/html; charset=UTF-8'>";
            _htmlDI += "</head>";
            _htmlDI += "<body>";

            #region Heading
            _htmlDI += "<table width='100%' cellpadding='1' cellspacing='1'>";

            _htmlDI += "<tr>";
            _htmlDI += "<td>&nbsp;</td>";
            _htmlDI += "<td colspan='25' align='left' style='font-size:16px;'><b>GG Daily Input</b></td>";
            _htmlDI += "<td colspan='2' align='left'><img src='http://www.gluaygluay.com/management/images/logos/gluaygluay_small.png' alt='gluaygluay' width='50px' height='40px' /></td>";
            _htmlDI += "</tr>";
            _htmlDI += "<tr><td colspan='28'>&nbsp;</td></tr>";
            _htmlDI += "<tr><td colspan='28'>&nbsp;</td></tr>";
            _htmlDI += "<tr><td colspan='28'>&nbsp;</td></tr>";
            _htmlDI += "</table>";
            #endregion

            _htmlDI += "<table width='100%' cellpadding='1' cellspacing='1'>";
            _htmlDI += "<tr><td colspan='28'>&nbsp;</td></tr>";
            _htmlDI += "</table>";

            #region Body
            _htmlDI += "<table width='100%' cellpadding='1' cellspacing='1' border='1'>";

            _htmlDI += "<tr>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Date</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Records</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Records</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Eff</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Contact</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Eff</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>ME</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>No ME</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Sales</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Sales</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Sales</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Sales</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Conv</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Conv</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>ANP</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>ANP</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>ANP</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>ANP</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Monthly</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Monthly</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Remaining</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Sales</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Records</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Records</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Records</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Recordings</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Penetration</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Penetration</b></td>";
            _htmlDI += "</tr>";

            _htmlDI += "<tr>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>&nbsp;</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Available</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Closed</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Contact</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Rate</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Contact</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Sign in</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>&nbsp;</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Records</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Policies</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Records</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Policies</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Rate</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Rate</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>&nbsp;</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Per</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Per</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Per</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Premium</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Premium</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Working</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Download</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Closed</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Received</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Loaded</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Delevered</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Rate</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Rate</b></td>";
            _htmlDI += "</tr>";

            _htmlDI += "<tr>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>&nbsp;</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>&nbsp;</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>&nbsp;</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>&nbsp;</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>&nbsp;</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>PHr</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Hr</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>&nbsp;</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>&nbsp;</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>&nbsp;</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>PHr</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>PHr</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>(Records)</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>(Policies)</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>&nbsp;</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Sale</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Policy</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Hr</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>&nbsp;</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Per Hr</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Days</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>&nbsp;</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Per Hr</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>&nbsp;</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>&nbsp;</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>To</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>(Records)</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>Policies)</b></td>";
            _htmlDI += "</tr>";
            for (int a = 0; a < _dsSummary.Tables[0].Rows.Count; a++)
            {
                _htmlDI += "<tr>";
                if (DayType[a].ToString() == "1")
                {
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; mso-number-format:dd\\-mmm\\-yyyy'>" + ReportDate[a].ToString() + "</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; mso-number-format:\\#\\,\\#\\#0'>" + RecAvailable[a].ToString() + "</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; mso-number-format:\\#\\,\\#\\#0'>" + RecClosed[a].ToString() + "</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; mso-number-format:\\#\\,\\#\\#0'>" + EffContact[a].ToString() + "</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px;'>" + ContactRate[a].ToString() + "%</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; mso-number-format:\\#\\,\\#\\#0'>" + SalesPolicies[a].ToString() + "</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px;'>" + ConversionRate[a].ToString("#0.00") + "%</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; mso-number-format:\\#\\,\\#\\#0\\.00'>" + ANP[a].ToString() + "</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; mso-number-format:\\#\\,\\#\\#0\\.00'>" + ANPperPolicy[a].ToString() + "</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; mso-number-format:\\#\\,\\#\\#0\\.00'>" + ANP[a].ToString() + "</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px;'>" + ReminingDays[a].ToString() + "</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px;'>" + PenetrationRate[a].ToString("#0.00") + "%</td>";
                }
                else
                {
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484; mso-number-format:dd\\-mmm\\-yyyy'>" + ReportDate[a].ToString() + "</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                    _htmlDI += "<td align='center' style='width:80px; font-size:10px; background-color:#848484;'>&nbsp;</td>";
                }
                _htmlDI += "</tr>";
            }

            _htmlDI += "<tr>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>" + _intTotalRecAvailable.ToString() + "</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>" + _intTotalRecClosed.ToString() + "</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>" + _intTotalEffContact.ToString() + "</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>" + _decTotalContactRate.ToString() + "%</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF; mso-number-format:\\#\\,\\#\\#0'><b>" + _intTotalSalesPolicies.ToString() + "</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF;'><b>" + _decTotalConversionRate.ToString("#0.00") + "%</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + _decTotalANP.ToString() + "</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + _decTotalANPperPolicy.ToString() + "</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF; mso-number-format:\\#\\,\\#\\#0\\.00'><b>" + _decTotalANP.ToString() + "</b></td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161;'>&nbsp;</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#0B2161; color:#FFFFFF'><b>" + _decTotalPenetrationRate.ToString("#0.00") + "%</b></td>";
            _htmlDI += "</tr>";

            _htmlDI += "</table>";
            #endregion

            _htmlDI += "<table width='100%' cellpadding='1' cellspacing='1'>";
            _htmlDI += "<tr><td colspan='28'>&nbsp;</td></tr>";
            _htmlDI += "</table>";

            _htmlDI += "<table width='100%' cellpadding='1' cellspacing='1'>";
            _htmlDI += "<tr><td colspan='28'>&nbsp;</td></tr>";
            _htmlDI += "</table>";

            _htmlDI += "<table width='100%' cellpadding='1' cellspacing='1'>";
            _htmlDI += "<tr><td colspan='28'>";
            _htmlDI += "<table width='100%' cellpadding='1' cellspacing='1' border='1'>";

            _htmlDI += "<tr>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#8181F7;'><b>A</b></td>";
            _htmlDI += "<td align='left' style='width:160px; font-size:10px;' colspan='2'>Contact Rate</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:10px;'>" + _decTotalContactRate.ToString() + "%</td>";
            _htmlDI += "</tr>";

            _htmlDI += "<tr>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#8181F7;'><b>C</b></td>";
            _htmlDI += "<td align='left' style='width:160px; font-size:10px;' colspan='2'>Conversion Rate (Sales)</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:10px;'>-</td>";
            _htmlDI += "</tr>";

            _htmlDI += "<tr>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#8181F7;'><b>T</b></td>";
            _htmlDI += "<td align='left' style='width:160px; font-size:10px;' colspan='2'>Conversion Rate (Policies)</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:10px;'>" + _decTotalConversionRate.ToString("#0.00") + "%</td>";
            _htmlDI += "</tr>";

            _htmlDI += "<tr>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#8181F7;'><b>U</b></td>";
            _htmlDI += "<td align='left' style='width:160px; font-size:10px;' colspan='2'>ANP Per Sale</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:10px;'>-</td>";
            _htmlDI += "</tr>";

            _htmlDI += "<tr>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#8181F7;'><b>A</b></td>";
            _htmlDI += "<td align='left' style='width:160px; font-size:10px;' colspan='2'>ANP Per Policy</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:10px;'>-</td>";
            _htmlDI += "</tr>";

            _htmlDI += "<tr>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#8181F7;'><b>L</b></td>";
            _htmlDI += "<td align='left' style='width:160px; font-size:10px;' colspan='2'>Pen Rate (Sales)</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:10px;'>-</td>";
            _htmlDI += "</tr>";

            _htmlDI += "<tr>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#8181F7;'>&nbsp;</td>";
            _htmlDI += "<td align='left' style='width:160px; font-size:10px;' colspan='2'>Pen Rate (Policies)</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:10px;'>" + _decTotalPenetrationRate.ToString("#0.00") + "%</td>";
            _htmlDI += "</tr>";

            _htmlDI += "<tr>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#8181F7;'><b>M</b></td>";
            _htmlDI += "<td align='left' style='width:160px; font-size:10px;' colspan='2'>Record Closed</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:10px; mso-number-format:\\#\\,\\#\\#0'>" + _intTotalRecClosed.ToString() + "</td>";
            _htmlDI += "</tr>";

            _htmlDI += "<tr>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#8181F7;'><b>T</b></td>";
            _htmlDI += "<td align='left' style='width:160px; font-size:10px;' colspan='2'>Sales Records</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:10px;'>-</td>";
            _htmlDI += "</tr>";

            _htmlDI += "<tr>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#8181F7;'><b>D</b></td>";
            _htmlDI += "<td align='left' style='width:160px; font-size:10px;' colspan='2'>Sales Policies</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:10px; mso-number-format:\\#\\,\\#\\#0'>" + _intTotalSalesPolicies.ToString() + "</td>";
            _htmlDI += "</tr>";

            _htmlDI += "<tr>";
            _htmlDI += "<td align='center' style='width:80px; font-size:11px; background-color:#8181F7;'>&nbsp;</td>";
            _htmlDI += "<td align='left' style='width:160px; font-size:10px;' colspan='2'>ANP</td>";
            _htmlDI += "<td align='center' style='width:80px; font-size:10px;'>-</td>";
            _htmlDI += "</tr>";

            _htmlDI += "</table>";
            _htmlDI += "</td></tr>";
            _htmlDI += "</table>";


            _htmlDI += "<table width='100%' cellpadding='1' cellspacing='1'>";
            _htmlDI += "<tr><td colspan='5'>&nbsp;</td></tr>";
            _htmlDI += "</table>";

            _htmlDI += "</body>";
            _htmlDI += "</html>";
            #endregion

            lblContent.Text = _htmlDI;
            ExportGridView(_fileName, lblContent);
        }
    }

    public void ExportGridView(string fileName, Label lblContent)
    {
        string attachment = "attachment; filename=" + fileName + ".xls";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/ms-excel";
        Response.Write(lblContent.Text);
        Response.End();
    }

}
